package com.horizon.common.controller;

import com.horizon.common.entity.IBaseEntity;
import com.horizon.common.service.IBaseService;

/**
 * 基本操作控制器接口
 *
 * @author wangfuwei
 * @version 2018-08-10
 */
public interface IBaseController {

    /**
     * 获取基本Service
     *
     * @return
     */
    IBaseService getBaseService();

    /**
     * 与数据库同步实体类
     *
     * @param entity
     * @param <T>
     * @return
     */
    default <T extends IBaseEntity> T syncEntity(IBaseEntity entity) {
        IBaseEntity baseEntity = getBaseService().syncEntity(entity);
        if (baseEntity == null) return null;
        return (T) baseEntity;
    }
}
